package com.tongji.housediy.view.components
{
	import mx.core.ILayoutElement;
	
	import spark.components.supportClasses.GroupBase;
	import spark.layouts.BasicLayout;
	import spark.layouts.TileLayout;
	import spark.layouts.VerticalLayout;
	import spark.layouts.supportClasses.LayoutBase;
	import com.tongji.housediy.view.renderer.SecondDropDownListRenerer;
	
	/**
	 * 
	 * @author chenchao
	 * 
	 */
	public class CustomLayout extends TileLayout
	{
		override public function updateDisplayList(width:Number, height:Number):void
		{	
			var layoutTarget:GroupBase = target;
			var count:int = layoutTarget.numElements;
			
			var customTop:int = 15;
			
			var xGap:int = 10;
			var yGap:int = 25;
			
			var customMaxWidth:int = 305;
			var lineWidth:int = 0;
			var lineCount:int = 0;
			
			for (var i:int = 0; i < count; i++)
			{
				var element:ILayoutElement = layoutTarget.getVirtualElementAt(i);
				if (lineWidth + xGap + (element as SecondDropDownListRenerer).btn.width > customMaxWidth)
				{
					lineWidth = 0;
					lineCount++;
				}
				
				element.setLayoutBoundsPosition(lineWidth + xGap, lineCount * yGap + customTop);
				lineWidth += (xGap + (element as SecondDropDownListRenerer).btn.width);
			}
			
			target.parent.parent.height = customTop + yGap * (lineCount + 1);
		}
	}
}